package com.ruoyi.lock.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.lock.domain.AWaringInfo;
import com.ruoyi.lock.mapper.AWaringInfoMapper;
import com.ruoyi.lock.service.IAWaringInfoService;
import com.ruoyi.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 预警信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-06
 */
@Service
public class AWaringInfoServiceImpl implements IAWaringInfoService 
{
    @Autowired
    private AWaringInfoMapper aWaringInfoMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;


    /**
     * 查询预警信息
     * 
     * @param id 预警信息主键
     * @return 预警信息
     */
    @Override
    public AWaringInfo selectAWaringInfoById(Long id)
    {
        return aWaringInfoMapper.selectAWaringInfoById(id);
    }

    /**
     * 查询预警信息列表
     * 
     * @param aWaringInfo 预警信息
     * @return 预警信息
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<AWaringInfo> selectAWaringInfoList(AWaringInfo aWaringInfo)
    {
        return aWaringInfoMapper.selectAWaringInfoList(aWaringInfo);
    }
    @Override
    @DataScope(deptAlias = "d")
    public List<AWaringInfo> selectAWaringInfoListAPP(AWaringInfo aWaringInfo)
    {
        return aWaringInfoMapper.selectAWaringInfoListApp(aWaringInfo);
    }

    /**
     * count数量
     * @return
     */
    @Override
    @DataScope(deptAlias = "d")
    public Integer selectAWaringInfoListCount(AWaringInfo aWaringInfo) {
        return aWaringInfoMapper.selectAWaringInfoListCount(aWaringInfo);
    }

    /** 告警数量 */
    @Override
    @DataScope(deptAlias = "d")
    public JSONObject gaoJinCount(AWaringInfo aWaringInfo) {
        return aWaringInfoMapper.gaoJinCount(aWaringInfo);
    }

    /** 告警数量 */
    @Override
    @DataScope(deptAlias = "d")
    public List<JSONObject> wujuzhu(AWaringInfo aWaringInfo) {
        List<JSONObject> wujuzhu = aWaringInfoMapper.wujuzhu(aWaringInfo);
        for (JSONObject jsonObject : wujuzhu) {
            //查询
            Long cellid = jsonObject.getLong("cellid");
            SysDept sysDept = sysDeptMapper.selectDeptById(cellid);
            jsonObject.put("cellName",sysDept.getDeptName());
        }
        return wujuzhu;
    }

    /**
     * 新增预警信息
     * 
     * @param aWaringInfo 预警信息
     * @return 结果
     */
    @Override
    public int insertAWaringInfo(AWaringInfo aWaringInfo)
    {
        aWaringInfo.setCreateTime(DateUtils.getNowDate());
        return aWaringInfoMapper.insertAWaringInfo(aWaringInfo);
    }

    /**
     * 修改预警信息
     * 
     * @param aWaringInfo 预警信息
     * @return 结果
     */
    @Override
    public int updateAWaringInfo(AWaringInfo aWaringInfo)
    {
        aWaringInfo.setUpdateTime(DateUtils.getNowDate());
        return aWaringInfoMapper.updateAWaringInfo(aWaringInfo);
    }

    /**
     * 批量删除预警信息
     * 
     * @param ids 需要删除的预警信息主键
     * @return 结果
     */
    @Override
    public int deleteAWaringInfoByIds(Long[] ids)
    {
        return aWaringInfoMapper.deleteAWaringInfoByIds(ids);
    }

    /**
     * 删除预警信息信息
     * 
     * @param id 预警信息主键
     * @return 结果
     */
    @Override
    public int deleteAWaringInfoById(Long id)
    {
        return aWaringInfoMapper.deleteAWaringInfoById(id);
    }
}
